Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): auto detect resolution #158

Merged
merged 2 commits into from
Mar 16, 2023
Merged

feat(cli): auto detect resolution #158

merged 2 commits into from
Mar 16, 2023

Conversation

jeertmans
Copy link
Owner

The present command will now read by default the resolution of each presentation, and only change it if specified by the user.

This PR also fixes bugs introduced by #156 and previous PRs, where the transition between two presentation was not correct...

The `present` command will now read by default the resolution of each presentation, and only change it if specified by the user.

This PR also fixes bugs introduced by #156 and previous PRs, where the transition between two presentation was not correct...
@jeertmans jeertmans added bug Something isn't working cli Related to the command line interface enhancement New feature or request present Related to the main "present" feature labels Mar 16, 2023
@jeertmans jeertmans temporarily deployed to github-pages March 16, 2023 12:50 — with GitHub Actions Inactive
@jeertmans
Copy link
Owner Author

Hello @Fairlight8, let me explain how this PR implements a similar feature as reading the default background color (here, the default resolution), and apply changes (see comments).

@jeertmans jeertmans temporarily deployed to github-pages March 16, 2023 13:09 — with GitHub Actions Inactive
Comment on lines 149 to +152
class PresentationConfig(BaseModel): # type: ignore
slides: List[SlideConfig]
files: List[FilePath]
resolution: Tuple[PositiveInt, PositiveInt] = (1920, 1080)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 first, I added a new resolution field. Specifying a default value is very important for backward compatibility (i.e., what to do when no resolution was specified? Use the default!).

Comment on lines +103 to +107
@property
def resolution(self) -> Tuple[int, int]:
"""Returns the resolution."""
return self.config.resolution

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 Second, add a property to Presentation so that Presentation.resolution maps to PresentationConfig.resolution

Comment on lines +723 to +729
@Slot()
def update_canvas(self) -> None:
"""Update the canvas when a presentation has changed."""
logger.debug("Updating canvas")
self.display_width, self.display_height = self.thread.current_resolution
if not self.isFullScreen():
self.resize(self.display_width, self.display_height)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 Third, every time the presentation changes, call to resize.
There, you will need to call setStyleSheet(...).

Comment on lines -841 to +883
default=(1920, 1080),
default=None,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 Fourth, set the default to None

Comment on lines -934 to +975
resolution: Tuple[int, int],
resolution: Optional[Tuple[int, int]],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 same as above, but for type hint

Comment on lines 1002 to 1005
if resolution:
for presentation_config in presentation_configs:
presentation_config.resolution = resolution

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 Fifth, update the configs if resolution is not None*

*Previously it was if resolution:, but testing if not None is better (because some values are also fasly, e.g., 0).

Comment on lines +57 to +64
@property
def __resolution(self) -> Tuple[int, int]:
"""Returns the scene's resolution used during rendering."""
if MANIMGL:
return self.camera_config["pixel_width"], self.camera_config["pixel_height"]
else:
return config["pixel_width"], config["pixel_height"]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 Sixth, create a new slide property that tells the resolution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why you have to add yet another property here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don’t « have to ». But as the definition depends on wether Manim or ManimGL is used, I prefer to hide the code behind a property :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay, I understand now. No worries, that was silly, I thought we still were in present.py. I understand now.

Comment on lines -315 to +325
PresentationConfig(slides=self.__slides, files=files).json(indent=2)
PresentationConfig(
slides=self.__slides, files=files, resolution=self.__resolution
).json(indent=2)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fairlight8 and finally add it to the constructor call :-)

@Fairlight8
Copy link
Contributor

Okay, I think I get it! You can push it, I will try to repeat the pattern for the background color.

@jeertmans
Copy link
Owner Author

Nice, thanks @Fairlight8 !

@jeertmans jeertmans merged commit 2a327c4 into main Mar 16, 2023
@jeertmans jeertmans deleted the resolution branch March 16, 2023 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to the command line interface enhancement New feature or request present Related to the main "present" feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants